package cn.jhc.sevlet;//到修改成绩信息页面

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.sql.Insert;

import cn.jhc.bean.Clazz;
import cn.jhc.bean.Score;
import cn.jhc.bean.Student;
import cn.jhc.dao.ClassDao;
import cn.jhc.dao.ScoreDao;
import cn.jhc.dao.StudentDao;
import cn.jhc.dao.impl.ClassDaoImpl;
import cn.jhc.dao.impl.ScoreDaoImp;
import cn.jhc.dao.impl.StudentDaoImpl;

/**
 * Servlet implementation class ToAlterscoreServlet
 */
@WebServlet("/user/teacher/toalterscore.do")
public class ToAlterscoreServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ToAlterscoreServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int scoreid = Integer.valueOf(request.getParameter("scoreid"));
		ScoreDao scoreDao = new ScoreDaoImp();
		Score score = (Score) scoreDao.get(scoreid);
		ClassDao classDao = new ClassDaoImpl();
		List<Clazz> clazzs = classDao.list();
		Set<String> clazznames = new HashSet<>();
		Set<String> clazzcolleges = new HashSet<>();
		for(int i=0;i<clazzs.size();i++){
			clazznames.add(clazzs.get(i).getName());
		}
		for(int i=0;i<clazzs.size();i++){
			clazzcolleges.add(clazzs.get(i).getCollege());
		}
		request.setAttribute("score", score);
		request.setAttribute("clazznames", clazznames);
		request.setAttribute("clazzcolleges", clazzcolleges);
		request.getRequestDispatcher("alterscore.jsp").forward(request,
				response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
